package com.tensquare.jwt;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;

import java.text.SimpleDateFormat;

public class ParseJwt {

    public static void main(String[] args) {
        Claims claims = Jwts.parser().setSigningKey("test")
                .parseClaimsJws("eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2NjY2NjYiLCJzdWIiOiLlsI_pqawiLCJpYXQiOjE1NTkyNzMzNTgsInJvbGUiOiJhZG1pbiJ9.-yr4v8QCVhEvk1aNobJthZdVXojdCyC9dVnhlgbHd0o")
                .getBody();
        System.out.println("用户Id：" + claims.getId());
        System.out.println("用户名：" + claims.getSubject());
        System.out.println("时间：" + new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(claims.getIssuedAt()));
        System.out.println("角色：" + claims.get("role"));
    }
}
